/**
 * 
 */

function addRow(){
	$("#editRow").dialog({
		title: "新增项目",
		iconCls: "icon-add",
		cache: false,
		modal: true,
		buttons:[{
			iconCls: 'icon-add',
			text: "新增保存",
			handler:function(){
				$('#formRow').form('submit',{
					url: uinsert,
					onSubmit: function(param){
						if ($(this).form('validate')) {
							$("body").easyMask('show');
						}else {
							return false;
						}
					},
					success: function(dd) {
						$('#dg').datagrid('reload');
						$("body").easyMask('hide');
						dd = eval('(' + dd + ')');
						if (dd.status>0) {
							$.messager.alert('',dd.info,'info');
							$("#editRow").dialog('close');
						}else {
							$.messager.alert('',dd.info,'error');
						}
					}
				});
			}
		},{
			iconCls: 'icon-cancel',
			text: "关闭",
			handler:function(){
				$("#editRow").dialog('close');
			}
		}],
		onClose: function(){
			$('#formRow').form('clear');
		},
		onBeforeOpen:function(){
			
		}
	});
}
//编辑记录
function editRow() {
	var row = $('#dg').datagrid('getSelected');
	//alert(JSON.stringify(row));
	if (row){
		
		$("#editRow").dialog({
			title: row.pro_code,
			iconCls: "icon-save",
			//height: 400,
			width: 350,
			cache: false,
			modal: true,
			buttons:[{
				iconCls: 'icon-save',
				text: "修改保存",
				handler:function(){
					$('#formRow').form('submit',{
						url: uupdate,
						onSubmit: function(param){
							if ($(this).form('validate')) {
								$("body").easyMask('show');
								param.id = row.id;
							}else {
								return false;
							}
						},
						success: function(dd) {
							$('#dg').datagrid('reload');
							$("body").easyMask('hide');
							dd = eval('(' + dd + ')');
							if (dd.status>0) {
								$.messager.alert('',dd.info,'info');
								$("#editRow").dialog('close');
							}else {
								$.messager.alert('',dd.info,'error');
							}
						}
					});
				}
			},{
				iconCls: 'icon-cancel',
				text: "关闭",
				handler:function(){
					$("#editRow").dialog('close');
				}
			}],
			onClose: function(){
				$('#formRow').form('clear');
			},
			onBeforeOpen: function () {
				$('#formRow').form('load',row);
				return true;
			}
			
		});
	}
}
//编辑审核信息
function editLook() {
	var row = $('#dg').datagrid('getSelected');
	//alert(JSON.stringify(row));
	if (row){
		$('#formLook').form('load',row);
		$("#editLook").dialog({
			title: row.pro_code,
			iconCls: "icon-save",
			height: 500,
			width: 760,
			resizable:true,
			cache: false,
			modal: true,
			buttons:[{
				iconCls: 'icon-save',
				text: "修改保存",
				handler:function(){
					myeditor.sync();
					$('#formLook').form('submit',{
						url: uupdatelook,
						onSubmit: function(param){
							if ($(this).form('validate')) {
								$("body").easyMask('show');
								param.id = row.id;
							}else {
								return false;
							}
						},
						success: function(dd) {
							$('#dg').datagrid('reload');
							$("body").easyMask('hide');
							dd = eval('(' + dd + ')');
							if (dd.status>0) {
								$.messager.alert('',dd.info,'info');
								$("#editLook").dialog('close');
							}else {
								$.messager.alert('',dd.info,'error');
							}
						}
					});
				}
			},{
				iconCls: 'icon-cancel',
				text: "关闭",
				handler:function(){
					$("#editLook").dialog('close');
				}
			}],
			onOpen: createEditor,
			onBeforeClose:function(){
				KindEditor.remove('#editor_content');
			},
			onClose: function(){
				$('#formLook').form('clear');
			}
		});
	}
}
function lookPass() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$('#dg').datagrid('loading');
		$.ajax({
			cache: false,
			type: "post",
			url: ulookpass,
			data: {id:row.id},
			async: true, //同步请求, 其它操作必须等待请求完成才可以执行
			success: function(dd) {
				if (dd.status) {
					$('#dg').datagrid('reload');
					$.messager.alert('',dd.info,'info');
				}else {
					$('#dg').datagrid('loaded');
					$.messager.alert('',dd.info,'error');
				}
			}
		});
	}
}
function jujue() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$('#dg').datagrid('loading');
		$.ajax({
			cache: false,
			type: "post",
			url: ujujue,
			data: {id:row.id},
			async: true, //同步请求, 其它操作必须等待请求完成才可以执行
			success: function(dd) {
				if (dd.status) {
					$('#dg').datagrid('reload');
					$.messager.alert('',dd.info,'info');
				}else {
					$('#dg').datagrid('loaded');
					$.messager.alert('',dd.info,'error');
				}
			}
		});
	}
}
//筛选查询
function gosearch() {
	$('#tb_search').form('submit',{
		onSubmit:function(){
			//做数据处理
			queryParams.protype = this.protype.value;
			queryParams.pro_code = this.pro_code.value;
			$('#dg').datagrid('load',queryParams);
			return false;
		}
	});
}

function typechange(rec) {
	$('#tb_search').form('submit',{
		onSubmit:function(){
			//做数据处理
			goclear();
			$('#tb_search').form('load',{protype:rec.value});
			queryParams.protype = rec.value;
			$('#dg').datagrid('load',queryParams);
			return false;
		}
	});
}

//放款
function fangkuan() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$('#dg').datagrid('loading');
		$.ajax({
			cache: false,
			type: "post",
			url: ufangkuan,
			data: {id:row.id},
			async: true, //同步请求, 其它操作必须等待请求完成才可以执行
			success: function(dd) {
				if (dd.status) {
					$('#dg').datagrid('reload');
					$.messager.alert('',dd.info,'info');
				}else {
					$('#dg').datagrid('loaded');
					$.messager.alert('',dd.info,'error');
				}
			}
		});
	}
}
//创建富文本编辑器
function createEditor(){
	myeditor = KindEditor.create('#editor_content', {
		urlType:'domain',
		allowFileManager : true,
		resizeType: 0,
		//autoHeightMode : true,
		afterCreate : function() {
			this.loadPlugin('autoheight');
		},
		afterUpload : function(url) {
			var firstimageoption = '<option value="' + url + '">' + url + '</option>';
			var selectoption = '<option value="' + url + '" selected="selected">' + url + '</option>';
			$("#firstimage").append(firstimageoption);
			$("#images").append(selectoption);
		}
	});
}